
*Kayran and Nadler - Political Behavior*
*Local alien enfranchisement and external efficacy perceptions: 
* intended and unintended effects on non-citizens and citizens*


cd "C:\Users\ENK\Desktop\Workingdirectory"

** Swiss Household Panel Analysis:
xtset idpers syear

bysort idpers (year2): gen first = 1 if _n==1 //first person-year
bysort idpers (year2): gen last = 1 if _n==_N // last person-year

summ age
drop if age<18 // respondents above 18 are kept in the sample

******************************************************
** Variables used in the analysis (see previous do-files for variable operationalisation):
******************************************************

*1: Immigrant, Native or Naturalised citizen: 
tab imgroup_v2

*2: Alien Enfranchisement
tab mvoting

gen mvoting_v2 = mvoting
replace mvoting_v2 = 0 if canton == 13 & year2 == 1999

*3: External efficacy:
** not available 10, 12, 13, 15, 16
generate ext_efficacy = p03_
tab p03_
tab ext_efficacy year

*4:Political interest:
* p01_ interest in politics
tab p01_
generate pol_interest = p01_ // higher values indicate more interest

*5: Political trust
** not available 10, 12, 13, 15, 16
generate pol_trust = p04_

*6 Household income:
tab income_h
gen income_house = income_h
recode income_house (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8=7) (9=8) (10=9)

*7 Work status
tab wstat 
* 1: active employed 2: unemployed 3: not in labour force

*8 Sex
tab sex 

gen woman = sex
recode woman (1=0) (2=1)

*9 Left-right ideology
tab p10_ syear
generate left_right = p10_ 
tab left_right // higher values mean more to the right

*10 Region of origin:
tab reg_1_

*11 union membership
tab n42_
label variable n42_ "union membership"

*12 religious participation
tab r04_
sum r04_
gen religion = r04_
recode religion (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8=7) (9=8)

label variable p10_ "left-right"
label variable e16_ "first language personal use"
label variable e17_ "second language for use"
**********************************

******************************************************
** Descriptive figures in the appendix.
******************************************************

*Figure B1
graph bar ext_efficacy if syear == 1999 | syear == 2004,  over(canton, sort(1) descending) over(syear)
*Figure B2
graph bar ext_efficacy if syear == 2009 | syear == 2014,  over(canton, sort(1) descending) over(syear)

** Figure of efficacy in different groups by AE:

graph bar ext_efficacy if syear == 2000 | syear == 2005 | syear == 2009 |syear == 2014, over(imgroup_v2) over(syear)

label define enfrancs 1 "AE" 0 "Non-AE"
label values mvoting_v2 enfrancs

tab mvoting syear, col

***************Figure for time trend
bysort syear imgroup_v2: egen dv_avg222= mean(ext_efficacy)
bysort syear imgroup_v2 mvoting_v2: egen dv_avgv333= mean(ext_efficacy)

twoway (tsline dv_avgv222 if mvoting_v2 == 1, by(imgroup) color(red)) (tsline dv_avgv2222 if mvoting == 0, by(imgroup) color(black))


******************************************************
** Summary statistics
******************************************************

summ ext_efficacy i.imgroup_v2 i.mvoting_v2 age woman edyear  income_house i.wstat  i.n42_ religion left_right pol_trust pol_interest i.origin syear i.canton

egen missing = rmiss(ext_efficacy imgroup_v2 age woman edyear income_house wstat syear canton )
egen missing2 = rmiss(ext_efficacy imgroup_v2 age woman edyear income_house wstat n42_ religion left_right pol_trust pol_interest origin syear canton )


summ ext_efficacy i.imgroup_v2 i.mvoting_v2 age woman edyear  income_house i.wstat if missing == 0 
summ i.n42_ religion left_right pol_trust pol_interest if missing2 == 0

summ ib2.imgroup_v2 ib2.wstat if missing == 0
summ ib2.n42_ if missing2 == 0

******************************************************
**Empirical Analysis**
******************************************************

****************************
*Table 1: Random Effects: 
*****************************

*Model 1
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 age woman edyear income_house i.wstat  i.syear i.canton ,  i(idpers)
outreg2 using "table1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

*Model 2
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 age woman edyear  income_house i.wstat  i.n42_ religion i.origin  i.syear i.canton ,  i(idpers)
outreg2 using "table1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

*Model 3
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 age woman edyear  income_house i.wstat  i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton ,  i(idpers)
outreg2 using "table1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

*Model 4
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 age woman edyear  income_house i.wstat  i.syear i.canton,  i(idpers)
outreg2 using "table1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
gen byte used_m4 =e(sample)


*Model 5
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 age woman edyear  income_house i.wstat i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton,  i(idpers)
outreg2 using "table1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
gen byte used_m5 =e(sample)


* Model 6 (without canton dummies)
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 age woman edyear  income_house i.wstat i.origin  i.syear ,  i(idpers)
outreg2 using "table1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

** estimate the group difference between NI & NNI:
xtreg ext_efficacy ib2.imgroup_v2 i.mvoting_v2 age woman edyear income_house i.wstat  i.syear i.canton ,  i(idpers)
xtreg ext_efficacy ib2.imgroup_v2 i.mvoting_v2 age woman edyear  income_house i.wstat  i.n42_ religion i.origin  i.syear i.canton ,  i(idpers)
xtreg ext_efficacy ib2.imgroup_v2 i.mvoting_v2 age woman edyear  income_house i.wstat  i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton ,  i(idpers)

************************
** Figure 1
************************
** visualisation of the interaction term AMEs(model 4):
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 age woman edyear  income_house i.wstat  i.syear i.canton,  i(idpers)
margins, dydx(mvoting_v2)  at(imgroup_v2=(1 2 3)) level(95)  vsquish post
estimates store model4
marginsplot, recast(scatter)  level(95) xline(0) horizontal


** In the appendix
** visualisation of the external efficacy predictors (model 3):

xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 age woman edyear  income_house i.wstat  i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton ,  i(idpers)
margins, dydx( mvoting_v2 age edyear income_house i.wstat  i.n42_ religion left_right pol_trust pol_interest) post
estimates store model3_othercovs

**including baselines
coefplot model3_othercovs ||, levels(90) base drop(_cons)  xtitle(Average Marginal Effects) ylabel(, labsize(medium)) xtitle("AMEs predicting external efficacy", size(medium)) byopts(xrescale) xline(0) 
** without baselines
coefplot model3_othercovs ||, levels(90) drop(_cons)  xtitle(Average Marginal Effects) ylabel(, labsize(medium)) xtitle("AMEs predicting external efficacy", size(medium)) byopts(xrescale) xline(0) 



******************************************
********Sensitivity Checks A**************

**********************************
** Fixed Effects:
**********************************
** Table F1:
xtreg ext_efficacy i.mvoting_v2, fe i(idpers)
outreg2 using "fixedeffects.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.mvoting_v2 if imgroup_v2 ==1, fe i(idpers)
outreg2 using "fixedeffects.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.mvoting_v2 if imgroup_v2 ==2, fe i(idpers)
outreg2 using "fixedeffects.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.mvoting_v2 if imgroup_v2 ==3, fe i(idpers)
outreg2 using "fixedeffects.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 


** Figure F1:
**Linear predictions of fixed effects:
xtreg ext_efficacy i.mvoting_v2, fe i(idpers)
margins, over (mvoting_v2) post 
estimates store FEbasepredict
xtreg ext_efficacy i.mvoting_v2 if imgroup_v2 ==1, fe i(idpers)
margins, over (mvoting_v2) post 
estimates store FEnatpredict
xtreg ext_efficacy i.mvoting_v2 if imgroup_v2 ==2, fe i(idpers)
margins, over (mvoting_v2) post 
estimates store FEnatimpredict
xtreg ext_efficacy i.mvoting_v2 if imgroup_v2 ==3, fe i(idpers)
margins, over (mvoting_v2) post 
estimates store FEbaseimmigpredicts
coefplot FEbasepredict ||FEnatpredict || FEnatimpredict || FEbaseimmigpredicts ||, levels(95) drop(_cons)  ylabel(, labsize(medium)) xtitle("Linear predictions of external efficacy", size(medium)) byopts(xrescale) 

**************************************************************************************
**************************************************************************************

** Narrowing down the difference between citizen vs. non-citizen
gen non_swiss = swiss
recode non_swiss (0=1) (1=0)
tab swiss imgroup_v2

** desriptive for the trends of efficacy
bysort syear canton: egen efficacy = mean(ext_efficacy)
bysort syear canton: egen efficacyfor = mean(ext_efficacy) if swiss == 0
bysort syear canton: egen efficacych = mean(ext_efficacy) if swiss == 1
twoway (tsline efficacych)(tsline efficacyfor), by(canton)


xtreg ext_efficacy i.mvoting_v2#i.swiss, fe i(idpers)
outreg2 using "tableF2.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
** Further narrowing down on the differences by taking out time trends:
xtreg ext_efficacy i.mvoting_v2#i.swiss i.syear, fe i(idpers)
outreg2 using "tableF2.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.mvoting_v2#i.swiss i.syear i.canton, fe i(idpers)
outreg2 using "tableF2.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 



************************************
** Figure 2: 
************************************

xtreg ext_efficacy i.mvoting_v2#i.swiss i.syear i.canton, fe i(idpers)
margins i.mvoting_v2#i.swiss, post level(95)  vsquish
marginsplot, xdim(swiss) plot(mvoting_v2) recast(bar) allx by(mvoting_v2) level(95)

******************************************
********Sensitivity Checks B**************


********************************************
************table G1:

* Muslim dummy
tab confession
gen confession = 9999
replace confession = p99r01 if syear == 1999
replace confession = p00r01 if syear == 2000
replace confession = p01r01 if syear == 2001
replace confession = p02r01 if syear == 2002
replace confession = p03r01 if syear == 2003
replace confession = p04r01 if syear == 2004
replace confession = p05r01 if syear == 2005
replace confession = p06r01 if syear == 2006
replace confession = p07r01 if syear == 2007
replace confession = p08r01 if syear == 2008
replace confession = p09r01 if syear == 2009
replace confession = p12r01 if syear == 2012
replace confession = p15r01 if syear == 2015
tab confession year 
recode confession (9999=.)

gen muslim = 99
replace muslim = 1 if confession == 6
replace muslim = 0 if confession == 1
replace muslim = 0 if confession == 2
replace muslim = 0 if confession == 3
replace muslim = 0 if confession == 4
replace muslim = 0 if confession == 5
replace muslim = 0 if confession == 7
replace muslim = 0 if confession == 8
replace muslim = 0 if confession == 9
replace muslim = 0 if confession == 10
replace muslim = 0 if confession == 11
replace muslim = 0 if confession == 12
tab muslim confession
recode muslim (99=.)

summ confession muslim

** * Duration of stay in Switzerland
** reg_1_ == 10 means Swiss
tab duration 
tab imgroup_v2

generate duratch = 9999
replace duratch = 1 if imgroup_v2 == 1 // benchmark will be native Swiss citizens
replace duratch = 2 if duration >=10  & imgroup_v2 != 1
replace duratch = 3 if duration<10 & duration>=5 &  imgroup_v2 != 1
replace duratch = 4 if duration<5  & imgroup_v2 != 1
recode duratch (9999=.)
tab duratch imgroup_v2

label define durations 1 "native" 2 "+10 years" 3 "5-10 years" 4 "<5 years"
label values duratch durations
tab duratch 

*Satisfaction with financial situation
tab i01_
gen finsat =  i01_

**


* Generalised trust (in people)
generate gen_trust = p45_
tab gen_trust // higher values mean more trust
*16: p02_ satisfaction with democracy
tab p02_ year
sum p02_
** not available 10, 12, 13, 15, 16
generate democ_satis = p02_

** the way it was constructed from wide to long:
tab p01ql04
gen satis_personalrel = 9999
replace satis_personalrel = p01ql04 if syear == 2001
replace satis_personalrel = p02ql04 if syear == 2002
replace satis_personalrel = p03ql04 if syear == 2003
replace satis_personalrel = p04ql04 if syear == 2004
replace satis_personalrel = p05ql04 if syear == 2005
replace satis_personalrel = p06ql04 if syear == 2006
replace satis_personalrel = p07ql04 if syear == 2007
replace satis_personalrel = p08ql04 if syear == 2008
replace satis_personalrel = p09ql04 if syear == 2009
replace satis_personalrel = p10ql04 if syear == 2010
replace satis_personalrel = p11ql04 if syear == 2011
replace satis_personalrel = p12ql04 if syear == 2012
replace satis_personalrel = p13ql04 if syear == 2013
replace satis_personalrel = p14ql04 if syear == 2014
replace satis_personalrel = p15ql04 if syear == 2015
replace satis_personalrel = p16ql04 if syear == 2016

tab satis_personalrel year 
recode satis_personalrel (9999=.)

** the way it was constructed from wide to long:

gen charity = 9999
replace charity = p99n45 if syear == 1999
replace charity = p00n45 if syear == 2000
replace charity = p01n45 if syear == 2001
replace charity = p02n45 if syear == 2002
replace charity = p03n45 if syear == 2003
replace charity = p04n45 if syear == 2004
replace charity = p05n45 if syear == 2005
replace charity = p06n45 if syear == 2006
replace charity = p07n45 if syear == 2007
replace charity = p08n45 if syear == 2008
replace charity = p09n45 if syear == 2009
replace charity = p11n45 if syear == 2011
replace charity = p14n45 if syear == 2014
tab charity year 
recode charity (9999=.)

*** Table G1
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 i.duratch age woman edyear  income_house i.wstat  i.syear i.canton ,  i(idpers)
outreg2 using "tableG1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 i.duratch age woman edyear  income_house i.wstat  i.syear i.canton,  i(idpers)
outreg2 using "tableG1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 muslim age woman edyear  income_house i.wstat  i.syear i.canton ,  i(idpers)
outreg2 using "tableG1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 muslim age woman edyear  income_house i.wstat i.origin i.syear i.canton ,  i(idpers)
outreg2 using "tableG1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 muslim age woman edyear  income_house i.wstat  i.syear i.canton,  i(idpers)
outreg2 using "tableG1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 finsat age woman edyear  income_house i.wstat  i.syear i.canton ,  i(idpers)
outreg2 using "tableG1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 finsat age woman edyear  income_house i.wstat  i.syear i.canton,  i(idpers)
outreg2 using "tableG1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

** political party member
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2  i.n43_ age woman edyear  income_house i.wstat  i.syear i.canton ,  i(idpers)
outreg2 using "TableG2.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2  i.n43_ age woman edyear  income_house i.wstat i.syear i.canton ,  i(idpers)
outreg2 using "TableG2.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2  i.n43_  age woman edyear  income_house i.wstat  i.syear i.canton,  i(idpers)
outreg2 using "TableG2.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
**charity membership
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2  i.charity age woman edyear  income_house i.wstat  i.syear i.canton ,  i(idpers)
outreg2 using "TableG2.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2  i.charity age woman edyear  income_house i.wstat  i.syear i.canton,  i(idpers)
outreg2 using "TableG2.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 


** satis personal relationships
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 satis_personalrel age woman edyear  income_house i.wstat  i.syear i.canton ,  i(idpers)
outreg2 using "TableG3.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 satis_personalrel  age woman edyear  income_house i.wstat i.syear i.canton,  i(idpers)
outreg2 using "TableG3.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

** generalised trust
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 gen_trust age woman edyear  income_house i.wstat  i.syear i.canton ,  i(idpers)
outreg2 using "TableG3.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 gen_trust age woman edyear  income_house i.wstat  i.syear i.canton,  i(idpers)
outreg2 using "TableG3.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

** sat democratic inst.
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 democ_satis age woman edyear  income_house i.wstat  i.syear i.canton ,  i(idpers)
outreg2 using "TableG3.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 democ_satis age woman edyear  income_house i.wstat i.syear i.canton,  i(idpers)
outreg2 using "TableG3.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 




*********************************************************************
********Sensitivity Checks - with municipal level data **************


** Creating a variable indicative of failed referandum in canton-year:

gen failed = 0 
replace failed = 1 if canton == 8 & year2 == 2001
replace failed = 1 if canton == 17 & year2 == 2001
replace failed = 1 if canton == 18 & year2 == 2005
replace failed = 1 if canton == 11 & year2 == 2007
replace failed = 1 if canton == 9 & year2 == 2010
replace failed = 1 if canton == 5 & year2 == 2010
replace failed = 1 if canton == 4 & year2 == 2010
replace failed = 1 if canton == 23 & year2 == 2011
replace failed = 1 if canton == 12 & year2 == 2011
replace failed = 1 if canton == 26 & year2 == 2013
replace failed = 1 if canton == 17 & year2 == 2014

summ vote
** replicating the model with share % of SVP vote in municipality:
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 vote  age woman edyear  income_house i.wstat i.syear i.canton,  i(idpers)
outreg2 using "TableG5.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 vote age woman edyear  income_house i.wstat i.syear i.canton,  i(idpers)
outreg2 using "TableG5.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 vote  age woman edyear  income_house i.wstat i.syear ,  i(idpers)
outreg2 using "TableG5.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 


xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 failed  age woman edyear  income_house i.wstat i.syear i.canton,  i(idpers)
outreg2 using "TableG5.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 failed  age woman edyear  income_house i.wstat i.syear i.canton,  i(idpers)
outreg2 using "TableG5.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 failed  age woman edyear  income_house i.wstat i.syear ,  i(idpers)
outreg2 using "TableG5.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

** Table G11
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 forpop_per  age woman edyear  income_house i.wstat i.syear i.canton,  i(idpers)
outreg2 using "TableG11.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 forpop_per  age woman edyear  income_house i.wstat i.syear i.canton,  i(idpers)
outreg2 using "TableG11.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 forpop_per  age woman edyear  income_house i.wstat i.syear ,  i(idpers)
outreg2 using "TableG11.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 


** Table G10 - removing Appenzell and Grisons


*Model 1
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 age woman edyear income_house i.wstat  i.syear i.canton if canton == 1 |  canton == 2 | canton == 4 | canton == 5 | canton == 6 | canton == 7| canton == 8 | canton == 9 | canton == 11 | canton == 12| canton == 13 | canton == 14 | canton == 15 | canton == 16| canton == 17 | canton == 18 | canton == 19 | canton == 20| canton == 21 | canton == 22 | canton == 23 | canton == 24| canton == 25 | canton == 26,  i(idpers)
outreg2 using "tableG10.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

*Model 2
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 age woman edyear income_house i.wstat  i.n42_ religion i.origin i.syear i.canton if canton == 1 |  canton == 2 | canton == 4 | canton == 5 | canton == 6 | canton == 7| canton == 8 | canton == 9 | canton == 11 | canton == 12| canton == 13 | canton == 14 | canton == 15 | canton == 16| canton == 17 | canton == 18 | canton == 19 | canton == 20| canton == 21 | canton == 22 | canton == 23 | canton == 24| canton == 25 | canton == 26,  i(idpers)
outreg2 using "tableG10.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

*Model 3
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 age woman edyear income_house i.wstat  i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton if canton == 1 |  canton == 2 | canton == 4 | canton == 5 | canton == 6 | canton == 7| canton == 8 | canton == 9 | canton == 11 | canton == 12| canton == 13 | canton == 14 | canton == 15 | canton == 16| canton == 17 | canton == 18 | canton == 19 | canton == 20| canton == 21 | canton == 22 | canton == 23 | canton == 24| canton == 25 | canton == 26,  i(idpers)
outreg2 using "tableG10.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

*Model 4
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 age woman edyear income_house i.wstat  i.syear i.canton if canton == 1 |  canton == 2 | canton == 4 | canton == 5 | canton == 6 | canton == 7| canton == 8 | canton == 9 | canton == 11 | canton == 12| canton == 13 | canton == 14 | canton == 15 | canton == 16| canton == 17 | canton == 18 | canton == 19 | canton == 20| canton == 21 | canton == 22 | canton == 23 | canton == 24| canton == 25 | canton == 26,  i(idpers)
outreg2 using "tableG10.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

*Model 5
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 age woman edyear income_house i.wstat  i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton if canton == 1 |  canton == 2 | canton == 4 | canton == 5 | canton == 6 | canton == 7| canton == 8 | canton == 9 | canton == 11 | canton == 12| canton == 13 | canton == 14 | canton == 15 | canton == 16| canton == 17 | canton == 18 | canton == 19 | canton == 20| canton == 21 | canton == 22 | canton == 23 | canton == 24| canton == 25 | canton == 26,  i(idpers)
outreg2 using "tableG10.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 


* Model 6
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 age woman edyear  income_house i.wstat i.origin  i.syear if canton == 1 |  canton == 2 | canton == 4 | canton == 5 | canton == 6 | canton == 7| canton == 8 | canton == 9 | canton == 11 | canton == 12| canton == 13 | canton == 14 | canton == 15 | canton == 16| canton == 17 | canton == 18 | canton == 19 | canton == 20| canton == 21 | canton == 22 | canton == 23 | canton == 24| canton == 25 | canton == 26 ,  i(idpers)
outreg2 using "tableG10.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 






******************************************
******************************************
********Sensitivity Checks**************


******************************************
******************************************
** Creating a variable indicative of years in the municipality of residence:
tab h00h02
gen residencesince = 9999
replace residencesince = h00h03 if syear == 2000
replace residencesince = h01h03 if syear == 2001
replace residencesince = h02h03 if syear == 2002
replace residencesince = h03h03 if syear == 2003
replace residencesince = h04h03 if syear == 2004
replace residencesince = h05h03 if syear == 2005
replace residencesince = h06h03 if syear == 2006
replace residencesince = h07h03 if syear == 2007
replace residencesince = h08h03 if syear == 2008
replace residencesince = h09h03 if syear == 2009
replace residencesince = h10h03 if syear == 2010
replace residencesince = h11h03 if syear == 2011
replace residencesince = h12h03 if syear == 2012
replace residencesince = h13h03 if syear == 2013
replace residencesince = h14h03 if syear == 2014
replace residencesince = h15h03 if syear == 2015
replace residencesince = h16h03 if syear == 2016

tab residencesince syear 
recode residencesince (9999=.)

gen timeinresidence = (year2-residencesince)
recode timeinresidence (-1=.)

summ timeinresidence

** determining municipality of residence at t-1:
by idpers: gen ofslag = ofs_[_n-1]
sum ofs_

gen move = 9999
replace move = 1 if ofs_ != ofslag & ofs_ !=. & ofslag!=.
replace move = 0 if ofs_ == ofslag & ofs_ !=. & ofslag!=.
tab move
recode move (9999=.)
xtsum move

tab move syear, col // indicates those who have moved

tab mvoting_v2 syear if missing == 0


gen movetoae = 9999 // move from t-1 resulted in living in a non-AE
                    //to AE municipality:
replace movetoae = 1 if mvoting_v2 == 1 &  ofs_ != ofslag & ofs_ !=. & ofslag!=.
replace movetoae = 0 if ofs_ == ofslag & ofs_ !=. & ofslag!=.
replace movetoae = 0 if mvoting_v2 == 0 & ofs_ != ofslag & ofs_ !=. & ofslag!=.
tab movetoae
recode movetoae(9999=.)

tab movetoae if missing == 0

*******************************************************
sort idpers
xtset idpers syear
by idpers: gen ae_lag = mvoting_v2[_n-1]
gen aechange = 1 if ae_lag != mvoting_v2 & ae_lag !=. & mvoting_v2 !=.
replace aechange = 0 if ae_lag == mvoting_v2 & ae_lag !=. & mvoting_v2 !=.
tab aechange

sort syear idpers
by syear: tab aechange movetoae
tab aechange movetoae, row if missing ==0


** Table G7:


*Model 1
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 move age woman edyear income_house i.wstat  i.syear i.canton ,  i(idpers)
outreg2 using "move.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
*Model 3
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 move age woman edyear  income_house i.wstat  i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton ,  i(idpers)
outreg2 using "move.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
*Model 4
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 move age woman edyear  income_house i.wstat  i.syear i.canton,  i(idpers)
outreg2 using "move.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
*Model 5
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 move age woman edyear  income_house i.wstat i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton,  i(idpers)
outreg2 using "move.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

*Model 1
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 move age woman edyear income_house i.wstat  i.syear i.canton if move !=1,  i(idpers)
outreg2 using "move.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
*Model 3
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 move age woman edyear  income_house i.wstat  i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton if move !=1,  i(idpers)
outreg2 using "move.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
*Model 4
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 move age woman edyear  income_house i.wstat  i.syear i.canton if move !=1,  i(idpers)
outreg2 using "move.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
*Model 5
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2 move age woman edyear  income_house i.wstat i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton if move !=1,  i(idpers)
outreg2 using "move.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 


** Table G8

xtreg ext_efficacy i.non_dual i.mvoting_v2 age woman edyear income_house i.wstat  i.syear i.canton ,  i(idpers)
outreg2 using "non_dual.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
*Model 3
xtreg ext_efficacy i.non_dual i.mvoting_v2 age woman edyear  income_house i.wstat  i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton ,  i(idpers)
outreg2 using "non_dual.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
*Model 4
xtreg ext_efficacy i.non_dual##i.mvoting_v2 age woman edyear  income_house i.wstat  i.syear i.canton,  i(idpers)
outreg2 using "non_dual.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
*Model 5
xtreg ext_efficacy i.non_dual##i.mvoting_v2 age woman edyear  income_house i.wstat i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton,  i(idpers)
outreg2 using "non_dual.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 


** Inverse probability weighting for panel attrition effects
bys idpers: egen stay= count(syear) if syear <=2014 & ext_efficacy !=.  // number of times the respondent participated in the survey
summ stay, detail // median 8
corr stay ext_efficacy // not correlated (0.0690)


gen med_att = 99
replace med_att = 1 if stay >=8
replace med_att = 0 if stay <8
tab med_att
tabstat ext_efficacy swiss sex age edyear income left_right pol_interest pol_trust r04_  religion wstat  if missing == 0, by(med_att) stat(mean sd min max) nototal long col(stat) 


xtlogit med_att age sex edyear income i.canton i.wstat i.imgroup_v2 i.syear if missing == 0, i(idpers) 
outreg2 using "Table_weight.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
predict p_att, pr
pwcorr p_att ext_efficacy mvoting 
/// correlate with efficacy -0.0089
                                   /// correlate with mvoting -0.0135
				// predicted probability is being above median participating (stay >8)

 
****************lags and leads
gen lag1 = mvoting[_n-1]

gen lead1 = mvoting[_n+1]

gen lead2 = mvoting[_n+2]

gen lead5 = mvoting[_n+5]

xtreg ext_efficacy i.imgroup_v2 lag1 age woman edyear  income_house i.wstat  i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton ,  i(idpers)
outreg2 using "Table_laglead.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.lag1 age woman edyear  income_house i.wstat i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton ,  i(idpers)
outreg2 using "Table_laglead.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

xtreg ext_efficacy i.imgroup_v2 lead1 age woman edyear  income_house i.wstat  i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton ,  i(idpers)
outreg2 using "Table_laglead.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 
xtreg ext_efficacy i.imgroup_v2##i.lead1 age woman edyear  income_house i.wstat i.n42_ religion left_right pol_trust pol_interest i.origin  i.syear i.canton,  i(idpers)
outreg2 using "Table_laglead.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

***********************************
************* Diff-in-Diff analysis ***************

*** Generate treatment variable: cantons with AE = 1, cantons without AE = 0
gen treatment = 0
replace treatment = 1 if canton == 3 | canton == 7 | canton == 8 | canton == 10 | canton == 11 | canton == 13 | canton == 23

*** Generate post treatment variable at 2000
gen post = .
replace post = 0 if canton == 1 | canton == 2 | canton == 4 | canton == 5 | canton == 6 | canton == 9 | canton == 12 | canton == 14 | canton == 15 | canton == 16 | canton == 17 | canton == 18 | canton == 19| canton == 20 | canton == 21 | canton == 22 | canton == 24 | canton == 25 | canton == 26

replace post = 1 if canton == 1 & syear > 2000 | canton == 2 & syear > 2000 | canton == 4 & syear > 2000 | canton == 5 & syear > 2000 | canton == 6 & syear > 2000 | canton == 9 & syear > 2000 | canton == 12 & syear > 2000   | canton == 14 & syear > 2000 | canton == 15 & syear > 2000  | canton == 16 | canton == 17 | canton == 18 | canton == 19| canton == 20 & syear > 2000  | canton == 21 & syear > 2000  | canton == 22 & syear > 2000  | canton == 24 & syear > 2000  | canton == 25 & syear > 2000 | canton == 26 & syear > 2000 

replace post = 0 if canton == 7 & syear <= 2006 | canton == 8 & syear <= 2005 | canton == 13 & syear <= 2000 | canton == 23 & syear <= 2002 

replace post = 1 if canton == 7 & syear > 2006 | canton == 8 & syear > 2005 | canton == 13 & syear > 2000 | canton == 23 & syear > 2002 

*** Generate post treatment variable at 2006

gen post_06 = .
replace post_06 = 0 if canton == 1 | canton == 2 | canton == 4 | canton == 5 | canton == 6 | canton == 9 | canton == 12 | canton == 14 | canton == 15 | canton == 16 | canton == 17 | canton == 18 | canton == 19| canton == 20 | canton == 21 | canton == 22 | canton == 24 | canton == 25 | canton == 26

replace post_06 = 1 if canton == 1 & syear > 2006 | canton == 2 & syear > 2006 | canton == 4 & syear > 2006 | canton == 5 & syear > 2006 | canton == 6 & syear > 2006 | canton == 9 & syear > 2006 | canton == 12 & syear > 2006   | canton == 14 & syear > 2006 | canton == 15 & syear > 2006  | canton == 16 | canton == 17 | canton == 18 | canton == 19| canton == 20 & syear > 2006  | canton == 21 & syear > 2006  | canton == 22 & syear > 2006  | canton == 24 & syear > 2006  | canton == 25 & syear > 2006 | canton == 26 & syear > 2006 

replace post_06 = 0 if canton == 7 & syear <= 2006 | canton == 8 & syear <= 2005 | canton == 13 & syear <= 2000 | canton == 23 & syear <= 2002 

replace post_06 = 1 if canton == 7 & syear > 2006 | canton == 8 & syear > 2005 | canton == 13 & syear > 2000 | canton == 23 & syear > 2002 


**** Models 

reg ext_efficacy i.treatment##i.post idpers i.canton  i.syear
reg ext_efficacy i.treatment##i.post_06 idpers i.canton  i.syear
reg ext_efficacy i.treatment##i.post idpers i.canton  i.syear age woman edyear  income_house i.n42_ religion left_right pol_trust pol_interest i.origin i.wstat
reg ext_efficacy i.treatment##i.post_06 idpers i.canton  i.syear age woman edyear  income_house i.n42_ religion left_right pol_trust pol_interest i.origin i.wstat


eststo: xtreg ext_efficacy i.treatment##i.post i.canton  i.syear, i(idpers)
eststo: xtreg ext_efficacy i.treatment##i.post_06 i.canton  i.syear, i(idpers)
eststo: xtreg ext_efficacy i.treatment##i.post  i.canton  i.syear age woman edyear  income_house i.n42_ religion left_right pol_trust pol_interest i.origin i.wstat, i(idpers)
eststo: xtreg ext_efficacy i.treatment##i.post_06 i.canton  i.syear age woman edyear  income_house i.n42_ religion left_right pol_trust pol_interest i.origin i.wstat, i(idpers)

esttab using Diff-in-Diff.rtf,  star(* 0.10 ** 0.05 *** 0.01)


*********************************
** 


** Estimations with the foreign population share interactions:

* Model 1
xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2 forpop_per age woman edyear  income_house i.wstat  i.n42_ religion i.origin  i.syear i.canton ,  i(idpers)
outreg2 using "table1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

* Model 2

xtreg ext_efficacy i.imgroup_v2 i.mvoting_v2##c.forpop_per age woman edyear  income_house i.wstat  i.n42_ religion i.origin  i.syear i.canton ,  i(idpers)
outreg2 using "table1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 

* Model 3
xtreg ext_efficacy i.imgroup_v2##c.forpop_per i.mvoting_v2  age woman edyear  income_house i.wstat  i.n42_ religion i.origin  i.syear i.canton ,  i(idpers)
outreg2 using "table1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 


* Model 4
xtreg ext_efficacy i.imgroup_v2##i.mvoting_v2##c.forpop_per age woman edyear  income_house i.wstat  i.n42_ religion i.origin  i.syear i.canton ,  i(idpers)
outreg2 using "table1.doc", word alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, t) bdec(2) label e(all) 




